import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout/index.vue'
import LayoutParentMenu from "../layout/LayoutParentMenu.vue"

Vue.use(VueRouter)

/**
 * meta 中存放路由信息描述
 * title：页面名称
 * groupName：组名
 */

const routes = [
  {
    path: '',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '/',
        name: 'home',
        meta: { requiresAuth: true, title: "首页" },
        component: () => import(/* webpackChunkName: "about" */ '../views/home/index.vue')
      },
      {
        path: '/dev',
        name: 'dev',
        meta: { requiresAuth: true, title: "开发项" },
        component: LayoutParentMenu,
        reject: "model-test",
        children: [
          {
            path: 'model-test',
            name: 'model-test',
            meta: { requiresAuth: true, title: "组件双向绑定" },
            component: () => import(/* webpackChunkName: "about" */ '../views/dev/model-test/index.vue'),
          },
          {
            path: 'model-test1',
            name: 'model-test1',
            meta: { requiresAuth: true, title: "组件双向绑定1" },
            component: () => import(/* webpackChunkName: "about" */ '../views/dev/model-test1/index.vue'),
          }
        ]
      }
    ]
  },
  {
    path: '*',
    name: '404',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../error/404')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // console.log("router-to", to)
  // console.log("router-from", from)
  next()
  // console.log("router-next",next)
})

export default router
